package com.hfzy.ihk.web.oauth.client.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by YANFA on 2019/1/29.
 */
@Controller
@Slf4j
public class LogoutController {

    /**
     * 登出调用接口
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("clearSession")
    @ResponseBody
    public String clearSession(HttpServletRequest request, HttpServletResponse response){
       // SecurityContextHolder.clearContext();
        try {
            new SecurityContextLogoutHandler().logout(request, null, null);
            log.info("=======================》登出成功");
        }catch (Exception e){
            log.error("=======================》登出失败",e);
        }
        return "成功";
    }
}
